package cn.stylefeng.guns.modular.productfunction.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.productfunction.entity.ShiProductFunction;
import cn.stylefeng.guns.modular.productfunction.model.params.ShiProductFunctionParam;
import cn.stylefeng.guns.modular.productfunction.model.result.ShiProductFunctionResult;
import cn.stylefeng.guns.modular.productfunction.service.ShiProductFunctionService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;


/**
 * 控制器
 *   产品功能表
 * @author 石博士
 * @Date 2019-07-05 14:38:37
 */
@Controller
@RequestMapping("/shiProductFunction")
public class ShiProductFunctionController extends BaseController {

    private String PREFIX = "/Shiproductfunction/shiProductFunction";

    @Autowired
    private ShiProductFunctionService shiProductFunctionService;

    /**
     * 跳转到主页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/index")
    public String index() {
        return PREFIX + "/shiProductFunction.html";
    }

    /**
     * 新增页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/shiProductFunction_add.html";
    }

    /**
     *点击产品对比时取到的id
     */
    @RequestMapping("/edit")
    public String edit(String id ,Model model) {
        model.addAttribute("id",id);
        //ShiProductFunction dan = shiProductFunctionService.getById(id);
        return PREFIX + "/shiProductFunction_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ShiProductFunctionParam shiProductFunctionParam) {
        this.shiProductFunctionService.add(shiProductFunctionParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ShiProductFunctionParam shiProductFunctionParam) {
        this.shiProductFunctionService.update(shiProductFunctionParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ShiProductFunctionParam shiProductFunctionParam) {
        this.shiProductFunctionService.delete(shiProductFunctionParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ShiProductFunctionParam shiProductFunctionParam) {
        ShiProductFunction detail = this.shiProductFunctionService.getById(shiProductFunctionParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 石博士
     * @Date 2019-07-05
     */
//    @ResponseBody
//    @RequestMapping("/list")
//    public LayuiPageInfo list(ShiProductFunctionParam shiProductFunctionParam) {
//        return this.shiProductFunctionService.findPageBySpec(shiProductFunctionParam);
//    }


    /**
     *产品对比接口
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/productComparison")
    @ResponseBody
    public ResponseData productComparison(String ids , Model model) {
        ShiProductFunctionResult dan = shiProductFunctionService.edit(ids);
        model.addAttribute("dan",dan);
        return ResponseData.success(dan);
    }


    /**
     * 使用左连接查询所有的功能对比数据
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ShiProductFunctionParam shiProductFunctionParam) {
        LayuiPageInfo lyp = new LayuiPageInfo();
        lyp.setData(shiProductFunctionService.ProductFunctionList());
        List<ShiProductFunctionResult> list = new ArrayList<>();
        list = shiProductFunctionService.ProductFunctionList();
        return lyp;
    }






}


